package benny.ApkposStore.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import benny.ApkposStore.R;
import benny.ApkposStore.utils.ApkUntils;

public class MainhttpActivity  extends Activity {
	    WebView mWebView;
		private Button returnButton;
	    /** Called when the activity is first created. */
	    @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	    	ApkUntils.fullscreen(this);
	        setContentView(R.layout.httpwebview);
	        
	        //实例化WebView对象 
	        mWebView = (WebView)findViewById(R.id.mWebView); 
	        //设置WebView属性，能够执行Javascript脚本 
	        mWebView.getSettings().setJavaScriptEnabled(true); 
	        //加载需要显示的网页 
	        mWebView.getSettings().setPluginsEnabled(true);
	        mWebView.getSettings().setAllowFileAccess(true);
	        mWebView.getSettings().setPluginsEnabled(true);
	        mWebView.getSettings().setPluginState(PluginState.ON);
	        //自适应屏幕大小

	        mWebView.getSettings().setUseWideViewPort(true);
	        mWebView.getSettings().setLoadWithOverviewMode(true);
	        // mWebView.getSettings().setPluginsPath("/data/data/" + getPackageName() + "/app_plugins/"); // 注意
	        mWebView.loadUrl("http://www.apkpos.com/");
	        
	        mWebView.setWebViewClient(new myWebViewClient());
	      //  setContentView(mWebView);
	        returnButton = (Button) findViewById(R.id.Return);
	        returnButton.setOnClickListener(new returnButtonListener());
	    }
	    
		@Override
		protected void onDestroy() {
			// TODO Auto-generated method stub
			System.gc(); // 回收系统资源
			super.onDestroy();
		}

		// 返回按钮监听器
		class returnButtonListener implements OnClickListener {

			@Override
			public void onClick(View v) {

				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(MainhttpActivity.this, ApkposStoreActivity.class);
				startActivity(intent);
				ApkUntils.openActivityAnim(MainhttpActivity.this,0);
				finish();
			}

		}
	    
	    private class myWebViewClient extends WebViewClient{
	   // 在WebView中而不是默认浏览器中显示页面 
	        @Override
	        public boolean shouldOverrideUrlLoading(WebView view, String url) {
	            // TODO Auto-generated method stub

	          view.loadUrl(url);
	            return true;
	        }
	        
	    }

	////下面代码没有添加，在我的手机里也隐藏地址栏了，但是有的设备可能还要加这些

	    @Override
	    public boolean onKeyDown(int keyCode, KeyEvent event) {
	        // TODO Auto-generated method stub
	        if((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
	        {
	            mWebView.goBack();
	            return true;
	        }
	        return super.onKeyDown(keyCode, event);
	    } 
	}